package com.example.medicalrecord.AggregationModule.medicine.controller;

import com.example.medicalrecord.AggregationModule.medicine.pojo.dto.MedicineParam;
import com.example.medicalrecord.AggregationModule.medicine.pojo.dto.MedicineQuery;
import com.example.medicalrecord.AggregationModule.medicine.pojo.vo.MedicineVO;
import com.example.medicalrecord.AggregationModule.medicine.service.MedicineService;
import com.example.medicalrecord.base.response.JsonResult;
import com.example.medicalrecord.base.response.PageData;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api
@RestController
@RequestMapping("/v1/medicine/")
public class MedicineController {
    @Autowired
    MedicineService medicineService;

    @GetMapping("select")
    public JsonResult selectMedicine(MedicineQuery medicineQuery){
        log.debug("查询药品类:medicineQuery={}",medicineQuery);
        PageData medicineVOList = medicineService.selectMedicine(medicineQuery);
        return JsonResult.ok(medicineVOList);
    }

    @PostMapping("save")
    public JsonResult saveMedicine(MedicineParam medicineParam){
        log.debug("保存药品类:MedicineParam={}",medicineParam);
        medicineService.saveMedicine(medicineParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{medicineId}")
    public JsonResult deleteMedicine(@PathVariable Long medicineId){
        log.debug("删除药品类:medicineId={}",medicineId);
        medicineService.deleteMedicine(medicineId);
        return JsonResult.ok();
    }
}
